<?php

namespace App\Console\Commands\Plane;

use App\Models\Plane\Cities\Repositories\Interfaces\PlaneCityRepositoryInterface;
use Illuminate\Console\Command;
use Maatwebsite\Excel\Facades\Excel;

class ImportPlaneCities extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'plane:cities:import';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '以excel为主导入机场城市';

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $planeCitiesRepo = app(PlaneCityRepositoryInterface::class);
        $file            = storage_path('plane/seeds/plane_cities.xlsx');
        $cities          = Excel::toArray(collect(), $file);
        unset($cities[0][0]);
        foreach ($cities[0] as $key => $c) {
            if (!$c[0] || !$c[1] || !$c[3] || !$c[4] || !$c[5] || !$c[6]) {
                $this->info("数据不全");
                var_dump($c);
                unset($cities[0][$key]);
                continue;
            }
            $planeCitiesRepo->addCity([
                'name'   => $c[1],
                'code'   => $c[0],
                'adcode' => $c[3],
            ]);

        }
    }
}
